<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head  th:replace="fragment :: head(~{::title})">
    <title>帖子详情</title>
</head>

<body>

<!--头部导航-->
<nav th:replace="fragment :: menu(0)" ></nav>

<!--中间内容-->
<div id="waypoint" class="m-container-small m-padded-tb-big animated fadeIn" style="width: 100%">
    <div class="ui container">
        <!--头部-->
        <div class="ui top attached segment">
            <div class="ui horizontal link list">
                <div class="item">
                    <img src="../static/images/bg1.jpeg" th:src="@{${forum.user.avatar}}" alt="" class="ui avatar image">
                    <div class="content"><a href="#" class="header" th:text="${forum.user.username}"></a></div>
                </div>
                <div class="item">
                    <i class="calendar icon"></i> <span th:text="${#dates.format(forum.createTime, 'yyyy-MM-dd')}">2017-10-01</span>
                </div>
                <div class="item">
                    <i class="eye icon"></i> <span th:text="${forum.views}">2342</span>
                </div>
                <div class="item">
                    <i class="at icon"></i> <span th:text="${forum.flag}">2342</span>
                </div>
                <div class="item">
                     <a th:href="@{/forum/like/{id}(id=${forum.id})}"><i class="thumbs up outline icon"></i></a><span th:classappend="${forum.like}==0?'hide':'pink'" th:text="${forum.like}">2342</span>
                </div>
                <div class="item">
                    <i class="bars icon"></i> <span th:each="tag : ${forum.tags}" th:text="${tag.name}">2342</span>
                </div>


            </div>
        </div>
        <div class="ui attached segment">
            <!--图片区域-->
            <img src="../static/images/bg1.jpeg" th:src="@{${forum.avatars}}" style="width: 100%;height: 400px" class="ui fluid rounded image">
        </div>
        <div class="ui  attached padded segment">
            <!--内容-->


            <h2 class="ui center aligned header" th:text="${forum.title}">关于刻意练习的清单</h2>
            <br>

            <!--中间主要内容部分-->
            <div id="content" class="typo  typo-selection js-toc-content m-padded-lr-responsive m-padded-tb-large" th:utext="${forum.content}">

                <h2 id="section1">一、关于 <i class="serif">Typo.css</i></h2>

                <pre><code class="language-css">p { color: red }</code></pre>

                <pre><code class="language-css">p { color: red }</code></pre>

                <p><i class="serif">Typo.css</i> 的目的是，在一致化浏览器排版效果的同时，构建最适合中文阅读的网页排版。</p>
                <h4 >现状和如何去做：</h4>

                <p class="typo-first">排版是一个麻烦的问题 <sup><a href="#appendix1"># 附录一</a></sup>，需要精心设计，而这个设计却是常被视觉设计师所忽略的。前端工程师更常看到这样的问题，但不便变更。因为在多个 OS 中的不同浏览器渲染不同，改动需要多的时间做回归测试，所以改变变得更困难。而像我们一般使用的
                    Yahoo、Eric Meyer 和 Alice base.css 中采用的 Reset 都没有很好地考虑中文排版。<i class="serif">Typo.css</i> 要做的就是解决中文排版的问题。</p>


                <h5 id="appendix2">2、开源许可</h5>

            </div>
        </div>
<!--        分享-->
        <div class="ui attached positive message">
            <div class="ui middle aligned grid">
                <div class="eleven wide column">
                    <ui class="list">
                        <li>作者：<span th:text="${forum.user.username}">code2ife</span></a></li>
                        <li>发表时间：<span th:text="${#dates.format(forum.createTime,'yyyy-MM-dd HH:mm:ss')}">2020-03-02 10:48</span></li>
<!--                        <li></li>-->
<!--                        <li></li>-->
<!--                        <li><button onclick="copyUrl()" class="btn-1"></button></li>-->
                    </ui>
                </div>
            </div>
        </div>
        <!--评论区  -->
    <div class="ui attached positive message" th:if="${forum.commentabled}">

        <div  class="ui bottom attached segment" >

            <div id="comment-container"  class="ui teal segment">
                <div th:fragment="commentList">
                    <div class="ui threaded comments" style="max-width: 100%;">
                        <h3 class="ui dividing header">评论</h3>
                        <div class="comment" th:each="comment : ${comments}" >
                            <a class="avatar">
                                <img src="https://unsplash.it/100/100?image=1005" th:src="@{${comment.avatar}}">
                            </a>
                            <div class="content">
                                <a class="author" >
                                    <span th:text="${comment.username}">Matt</span>
<!--                                    <div class="ui mini basic teal left pointing label m-padded-mini" th:if="${comment.username}">博主</div>-->
                                </a>

                                <div class="metadata">
                                    <span class="date" th:text="${#dates.format(comment.createTime,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>
                                </div>
                                <div class="text" th:text="${comment.content}">
                                    How artistic!
                                </div>
                                <div class="actions">
                                    <a class="reply" data-commentid="1" data-commentusername="Matt" th:attr="data-commentid=${comment.id},data-commentusername=${comment.username}" ></a>
<!--                                    <a class="reply" data-commentid="1" data-commentusername="Matt" th:attr="data-commentid=${comment.id},data-commentusername=${comment.username}" onclick="reply(this)">回复</a>-->
                                </div>
                            </div>
                            <!--子集评论-->
<!--                            <div class="comments">-->
<!--                                <div class="comment">-->
<!--                                    <a class="avatar">-->
<!--                                        <img src="../static/images/avatar.png">-->
<!--                                    </a>-->
<!--                                    <div class="content">-->
<!--                                        <a class="author" >-->
<!--                                            <span>小红</span>-->
<!--                                            <div class="ui mini basic teal left pointing label m-padded-mini">栈主</div>-->
<!--                                            &nbsp;<span class="m-teal">@ 小白</span>-->
<!--                                        </a>-->
<!--                                        <div class="metadata">-->
<!--                                            <span class="date">Today at 5:42PM</span>-->
<!--                                        </div>-->
<!--                                        <div class="text">-->
<!--                                            How artistic!-->
<!--                                        </div>-->
<!--                                    </div>-->
<!--                                </div>-->
<!--                            </div>-->
<!--                            <div class="comments" th:if="${#arrays.length(comment.replyComments)}>0">-->
<!--                                <div class="comment" th:each="reply : ${comment.replyComments}" >-->
<!--                                    <a class="avatar">-->
<!--                                        <img src="https://unsplash.it/100/100?image=1005" th:src="@{${reply.avatar}}">-->
<!--                                    </a>-->
<!--                                    <div class="content">-->
<!--                                        <a class="author" >-->
<!--                                            <span th:text="${reply.username}">Matt</span>-->
<!--                                            <span th:text="${reply.parentComment.username}" style="color: red"></span>-->
<!--                                            &lt;!&ndash;                                    <div class="ui mini basic teal left pointing label m-padded-mini" th:if="${comment.username}">博主</div>&ndash;&gt;-->
<!--                                        </a>-->

<!--                                        <div class="metadata">-->
<!--                                            <span class="date" th:text="${#dates.format(reply.create_time,'yyyy-MM-dd HH:mm')}">Today at 5:42PM</span>-->
<!--                                        </div>-->
<!--                                        <div class="text" th:text="${reply.content}">-->
<!--                                            How artistic!-->
<!--                                        </div>-->
<!--                                        <div class="actions">-->
<!--                                            <a class="reply" data-commentid="1" data-commentusername="Matt" th:attr="data-commentid=${comment.id},data-commentusername=${comment.username}" onclick="reply(this)">回复</a>-->
<!--                                        </div>-->
<!--                                    </div>-->
<!--                                    <div class="comments">-->
<!--                                    </div>-->
<!--                                </div>-->

                            </div>
                        </div>

                    </div>
                </div>
            </div>

            <!--评论表单-->
            <div id="comment-form" class="ui form">
<!--                <form th:action="@{comments}">-->
                <input type="hidden"  name="forum.id" th:value="${forum.id}">
                <input type="hidden" name="parentComment.id" value="-1">
                <div class="field">
                    <textarea name="content"  placeholder="请输入评论信息..."></textarea>
                </div>
                <div class="fields">
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="user icon"></i>
                            <input type="text" name="username" placeholder="姓名" th:value="${session.user}!=null ? ${session.user.username}">
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="mail icon"></i>
                            <input type="text" name="email" placeholder="邮箱" th:value="${session.user}!=null ? ${session.user.email}">
                        </div>
                    </div>
                    <div class="field  m-margin-bottom-small m-mobile-wide">
                        <button id="commentpost-btn" type="button" class="ui teal button m-mobile-wide"  ><i class="edit icon"></i>评论</button>
                    </div>
                </div>
<!--                </form>-->
            </div>

        </div>
    </div>
</div>


<div class="ui toc-container flowing popup transition hidden" style="width: 250px!important;">
    <ol class="js-toc">

    </ol>
</div>

<div id="qrcode" class="ui wechat-qr flowing popup transition hidden "style="width: 130px !important;">
    <img src="./static/images/wechat.jpg"  th:src="@{/images/wechat.jpg}" alt=""  class="ui rounded image" style="width: 120px !important;">
</div>
</div>


<br>
<br>
<footer th:replace="fragment :: footer" class="ui inverted vertical segment m-padded-tb-massive" />
<!--<span id="user_like" th:text="${like}==1?'like':''"></span>-->
<!--底部footer-->


<!--    <script src="../static/dist/clipboard.js" th:src="@{/dist/clipboard.js}"></script>-->
<!--    <script src="../static/dist/clipboard.min.js" th:src="@{/dist/clipboard.min.js}"></script>-->
    <script src="https://cdn.jsdelivr.net/npm/clipboard@2/dist/clipboard.min.js"></script>
<script th:inline="javascript">
<!--    敏感词-->



    function copyUrl(){
        const aux = document.createElement('input')
        const href = window.location.href
        aux.setAttribute('value', href)
        document.body.appendChild(aux)
        aux.select()
        document.execCommand('copy')
        document.body.removeChild(aux)
        if (href==null){
            alert("请直接从网址中复制链接！")
        }else {
            alert("复制成功！")
        }

    };

    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');

    });

    $('#payButton').popup({
        popup : $('.payQR.popup'),
        on : 'click',
        position: 'bottom center'
    });

    tocbot.init({
        // Where to render the table of contents.
        tocSelector: '.js-toc',
        // Where to grab the headings to build the table of contents.
        contentSelector: '.js-toc-content',
        // Which headings to grab inside of the contentSelector element.
        headingSelector: 'h1, h2, h3',
    });

    $('.toc.button').popup({
        popup : $('.toc-container.popup'),
        on : 'click',
        position: 'left center'
    });

    $('.wechat').popup({
        popup : $('.wechat-qr'),
        position: 'left center'
    });

    var serurl = /*[[#{forum.serurl}]]*/"127.0.0.1:8080";
    var url = /*[[@{/forum/{id}(id=${forum.id})}]]*/"";
    var qrcode = new QRCode("qrcode", {
        text: serurl+url,
        width: 110,
        height: 110,
        colorDark : "#000000",
        colorLight : "#ffffff",
        correctLevel : QRCode.CorrectLevel.H
    });

    $('#toTop-button').click(function () {
        $(window).scrollTo(0,500);
    });


    var waypoint = new Waypoint({
        element: document.getElementById('waypoint'),
        handler: function(direction) {
            if (direction == 'down') {
                $('#toolbar').show(100);
            } else {
                $('#toolbar').hide(500);
            }
            console.log('Scrolled to waypoint!  ' + direction);
        }
    })


    //评论表单验证
    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '请输入评论内容'
                }
                ]
            },
            content: {
                identifier: 'username',
                rules: [{
                    type: 'empty',
                    prompt: '请输入你的昵称'
                }]
            },
            type: {
                identifier: 'email',
                rules: [{
                    type: 'email',
                    prompt: '请填写正确的邮箱地址'
                }]
            }
        }
    });

    $(function () {

        $("#comment-container").load(/*[[@{/comments/{id}(id=${forum.id})}]]*/"comments/6");
    });


    //校验
    $('#commentpost-btn').click(function () {
        var boo = $('.ui.form').form('validate form');
        if (boo) {
            console.log('表单校验成功');
            postData();
        } else {
            console.log('校验失败');
        }

    });


    function postData() {
        $("#comment-container").load(/*[[@{/comments}]]*/"",{
            "parentComment.id" : $("[name='parentComment.id']").val(),
            "forum.id" : $("[name='forum.id']").val(),
            "username": $("[name='username']").val(),
            "email"   : $("[name='email']").val(),
            "content" : $("[name='content']").val()
        },function (responseTxt, statusTxt, xhr) {
//        $(window).scrollTo($('#comment-container'),500);
            clearContent();
        });
    }

    function clearContent() {
        $("[name='content']").val('');
        $("[name='parentComment.id']").val(-1);
        $("[name='content']").attr("placeholder", "请输入评论信息...");
    }


    function reply(obj) {
        var commentId = $(obj).data('commentid');
        var commentNickname = $(obj).data('commentusername');
        $("[name='content']").attr("placeholder", "@"+commentNickname).focus();
        $("[name='parentComment.id']").val(commentId);
        $(window).scrollTo($('#comment-form'),500);
    }


</script>

</body>
</html>
